home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15524 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is wrong with this loop?
  5. Date: 19 Apr 1996 15:16:58 GMT
  6. Organization: OpenVision
  7. Message-ID: <4l8apa$kv8@spanky.pls.ov.com>
  8. References: <4l86la$1t9@uwm.edu>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 1t9@uwm.edu, mardavuy@alpha2.csd.uwm.edu (Mario David Uy) writes:
  13. >#include <stdio.h>
  14. >int main(void)
  15. >{
  16. >   int dia;
  17. >
  18. >   char cd;
  19. >
  20. >   ...
  21. >
  22. >   scanf("%c", &cd);
  23. >   while (cd != 'm' || cd ! 'f' || cd != 'o')
  24. >    {
  25. >    printf("Re-enter m, f, or o.\n");
  26. >    scanf(%c", &cd);
  27. >    }
  28. >   ...
  29. >}
  30. >
  31. >It works fine, except that it gives me the printf() twice.
  32. >
  33. >David
  34. >mardavuy@csd.uwm.edu
  35. >-- 
  36. >-------------------------------------------------------------------------------
  37. >||                                          ||Is it gonna be hide or seek,   ||
  38. >||  Mario David Uy                          ||  is it gonna be win or lose?  ||
  39. >||      mardavuy@csd.uwm.edu                ||Is it gonna be pride that keeps||
  40.  
  41.  
  42. My bet is that you have forgotten that the '\n' in your input is
  43. also a character.  Try changing your while statement from:
  44.  
  45.    while (cd != 'm' || cd ! 'f' || cd != 'o')
  46.  
  47. to:  while(cd != 'm' || cd != 'f' || cd != 'o' || cd != '\n')
  48.  
  49.         Fletcher.Glenn@ov.com
  50.  
  51.  
  52.  
  53.